package xgoogauth

import (
	"fmt"
	"strings"
	"time"
)

// 根据秘钥获取随机数字验证码
//
//	secret	秘钥标识
func Get(secret string) string {
	if secret == "" {
		return ""
	}
	secretUpper := strings.ToUpper(secret)
	secretKey, err := base32decode(secretUpper)
	if err != nil {
		_default.LogErrorFunc("谷歌秘钥Code获取失败", err)
		return ""
	}
	number := oneTimePassword(secretKey, toBytes(time.Now().Unix()/30))
	return fmt.Sprintf("%06d", number)
}
